#pragma once
#include "IO.hpp"

class processObject
{
    string user;
    string passWord;
    string JS;
    string result;
public:
    processObject(string user,string passWord,string JS){
        this->user=user;
        this->passWord=passWord;
        this->JS=JS;
    }

    processObject(){}

    void setUser(const string& username){
        this->user=username;
    }

    string getUser()const{
        return user;
    }

    void setPassword(const string& password){
        this->passWord=passWord;
    }

    string getPassWord()const{
        return passWord;
    }

    void setJS(const string& JS){
        this->JS=JS;
    }

    string getJS()const{
        return JS;
    }

    void setResult(const string& result){
        this->result=result;
    }

    string getResult()const{
        return result;
    }
};



class logger{
public :
    static string logFileName;

    static fstream logFile;

    static string getLogStr(const processObject& pObject){
        string resStr="";
        resStr.append("UserName:"+pObject.getUser()+"\n");
        resStr.append("PassWord:"+pObject.getPassWord()+"\n");
        resStr.append("Request Code:"+pObject.getJS()+"\n");
        resStr.append("Response Result:\n"+pObject.getResult()+"\n"+"\n");
        return resStr;
    }

    static void writeLog(const processObject& pObject){
        logFile=fstream (IO::default_path+"\\"+logger::logFileName+".txt",ios::out|ios::app);
        if (!logFile.is_open())
            throw string("fail to open the file(write)");
        logFile << getLogStr(pObject);
        logFile.close();
    }
};
